package com.swg.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

import java.util.Arrays;

@Aspect
public class LogAspect {

    @Pointcut("execution(public int com.swg.aop.MathCaculator.*(..))")
    public void pointCut(){}

    @Before("pointCut()")
    public void logStart(JoinPoint joinPoint){
        String methodName = joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        System.out.println("【@Before】...方法名：{"+methodName+"}...参数列表是->{"+ Arrays.asList(args)+"}");

    }

    @After("pointCut()")
    public void logEnd(JoinPoint joinPoint){
        System.out.println("【@After】...{"+joinPoint.getSignature().getName()+"}结束...");
    }

    @AfterReturning(value = "pointCut()",returning = "result")
    public void logReturn(JoinPoint joinPoint,Object result){
        System.out.println("【@AfterReturning】...{"+joinPoint.getSignature().getName()+"}正常返回，运行结果是{"+result+"}");
    }

    @AfterThrowing(value = "pointCut()",throwing = "exception")
    public void logException(JoinPoint joinPoint,Exception exception){
        System.out.println("【@AfterThrowing】...{"+joinPoint.getSignature().getName()+"}发生异常,异常信息是{"+exception.getMessage()+"}");
    }

}
